//
//  OuptCheckInfoVC.m
//  掌上宏力
//
//  Created by admin on 2017/5/8.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "CheckInfoViewController.h"
#import "CheckInfoFrame.h"
#import "CheckInfoModel.h"
#import "CheckInfoCell.h"
#import "CheckDetailInfoVC.h"
#import "CheckInfoViewModel.h"

@interface CheckInfoViewController ()

@property (nonatomic,strong) CheckInfoViewModel *viewModel;

@end

@implementation CheckInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)getDatasArray{
    [self getDatasArray:^(NSString *page, GetDatas handler) {
        _viewModel = [[CheckInfoViewModel alloc] init];
        _viewModel.patientSource = self.patientSource;
        [_viewModel getCheckInfoSuccess:^{
            if (self.currentPage == 1) {
                handler(_viewModel.datasArray);
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }else{
                handler([NSArray array]);
            }
         
        }];
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _viewModel.datasArray.count;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    CheckInfoFrame *checkInfoF = _viewModel.datasArray[section];
    CheckInfoModel *model = checkInfoF.checkInfo;
    return model.exam_date;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CheckInfoFrame *frame = _viewModel.datasArray[indexPath.section];
    return frame.cellHeight;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    CheckDetailInfoVC *detailVC = [[CheckDetailInfoVC alloc] init];
    CheckInfoFrame *info = _viewModel.datasArray[indexPath.section];
    detailVC.infoModel = info.checkInfo;
    [self pushViewControllerTo:detailVC];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CheckInfoCell *cell = [CheckInfoCell cellWithTableView:tableView];
    cell.checkInfoFrame = _viewModel.datasArray[indexPath.section];
    return cell;
}


@end
